import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description：
 * User：user
 * DATE:2021-11-01
 * Time:18:25
 */
class Card{
    public int rank;//牌面值
    public String suit;//花色

    public Card(int rank, String suit) {
        this.rank = rank;
        this.suit = suit;
    }

    @Override
    public String toString() {
        return "[" + suit + " "+rank+"]";
    }
}
class CardDemo{
    private static final String[] suits = {"♥","♠","♦","♣"};

    //买牌操作
    public List<Card> buyDesc(){
        List<Card> cards = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            for (int j = 1; j <= 13; j++) {
                String suit = suits[i];
                Card card = new Card(j,suit);
                cards.add(card);
            }
        }
        return cards;
    }

    public void swap(List<Card> cardList,int i ,int j){
            Card tmp = cardList.get(i);
            cardList.set(i,cardList.get(j));
            cardList.set(j,tmp);
    }

    //洗牌操作
    public void shuffle(List<Card> cardList){
        for (int i = cardList.size() - 1; i > 0 ; i--) {
            Random random = new Random();
            int j = random.nextInt(i);
            swap(cardList,i,j);
        }
    }

    public void func(List<Card> cardList){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();

        List< List<Card>> hand = new ArrayList<>();
        hand.add(hand1);//hand的每一个元素都是List
        hand.add(hand2);
        hand.add(hand3);

        //3个人 每个人，轮流揭牌5张>>总共每个人揭牌5次 轮流
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card  = cardList.remove(0);
                hand.get(j).add(card);
            }
        }
        System.out.println("揭牌：");
        for (int i = 0; i < hand.size(); i++) {
            for (int j = 0; j < hand.get(i).size(); j++) {
                System.out.print(hand.get(i).get(j));
            }
            System.out.println("");
        }
    }


}
public class TestDemo5 {
    public static void main(String[] args) {
        CardDemo cardDemo = new CardDemo();
        List<Card> cardList = cardDemo.buyDesc();
        System.out.println(cardList);
        cardDemo.shuffle(cardList);
        System.out.println(cardList);
        cardDemo.func(cardList);
    }
}
